﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace 自定义配置系统
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //var configBuilder = new ConfigurationBuilder();
            //configBuilder.Add(new LmConfigSource() { Path="appsetting.json" });
            //var config = configBuilder.Build();
            //string addr = config["Address"];
            //string port = config.GetSection("Port").Value;
            //Console.WriteLine($"Address={addr}");
            //Console.WriteLine($"Port={port}");

            //var builder = new ConfigurationBuilder();
            //builder.UseLmConfig();

            ServiceCollection services = new ServiceCollection();
            services.AddScoped<IConfiguration>(serviceProvider =>
                new ConfigurationBuilder().UseLmConfig()
            );
            services.AddScoped<TestController>();
            services.AddScoped<LmConfigProvider>();
            services.AddScoped<LmConfigSource>();

            using (var sp = services.BuildServiceProvider())
            {
                var test = sp.GetRequiredService<TestController>();
                test.Test();
            }

            Console.ReadKey();
        }
    }
}
